import java.io.File;
import java.io.IOException;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class SpreadsheetMaker {

	public void makeSpreadsheet(double[][] runTimes, String[] labels,
			int[] intervalBoundarys) throws IOException, RowsExceededException,
			WriteException {

		WritableWorkbook wworkbook;
		WritableSheet wsheet;
		Number number;
		Label label;
		wworkbook = Workbook.createWorkbook(new File("SortRunTimes.xls"));
		wsheet = wworkbook.createSheet("sorting algorithms", 0);

		for (int i = 0; i < labels.length; i++) {
			label = new Label(i + 1, 0, labels[i] + "sort");
			number = new Number(i + 1, 1, 0);
			wsheet.addCell(label);
			wsheet.addCell(number);
		}
		for (int i = 0; i < intervalBoundarys.length; i++) {
			number = new Number(0, i + 1, intervalBoundarys[i]);
			wsheet.addCell(number);
		}
		for (int j = 0; j < labels.length; j++) {
			for (int i = 0; i < intervalBoundarys.length - 1; i++) {
				number = new Number(j + 1, i + 2, Math.floor(runTimes[j][i]));
				wsheet.addCell(number);
			}
		}
		wworkbook.write();
		wworkbook.close();
	}
}
